<%@page import="java.util.Date"%>
<%@page import="board.BoardVo"%>
<%@page import="java.util.Vector"%>
<%@page import="board.Board"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Inzy's Board</title>
<link rel="stylesheet"
	href="http://fonts.googleapis.com/earlyaccess/nanumgothic.css" />
<style>

#list_input, #board_list_frm input[type=submit] {
	font-size: 14px;
	font-family: 'Nanum Gothic', sans-serif;
	background: #160952;
	color: white;
	border: 4px solid #160952;
	cursor:pointer;
}

#board_list_frm{
	text-align: right;
}

#board_h1{
	font-family: 'Nanum Gothic', sans-serif;
	font-weight: bold;	
	background-color: #ffaeaf;
	width: 250px;
}

#board_pos {
	width: 740px;
	height: 520px;
	padding-top: 50px;
	font-size : 12px;
	background-color: transparent;
	color: white;
}

#board_main {
 	background-size: 100%;
	background-image: url(../images/boardbg-2.png);
	background-color: white;
	width: 100%;
	height: 570px;
}

/* title */
#list_no,#list_subject,#list_id,#list_date,#list_count {
	line-height: 250%; /* 줄 간격 */
	display: table-cell;
	background-color: #160952;
	font-family: 'Nanum Gothic', sans-serif;
	font-size: 14px;
}

#list_no {
	width: 70px;
}

#list_subject {
	width: 300px;
}

#list_id {
	width: 100px;
}

#list_date {
	width: 200px;
}

#list_count {
	width: 70px;
}

#list_line {
	width: 740px;
	height: 1px;
}

/* cell */
.item_no,.item_subject,.item_id,.item_date,.item_count {
	display: table-cell;
	line-height: 200%; /* 줄 간격 */
	font-family: 'Nanum Gothic', sans-serif;
	font-size: 13px;
	color: black;
}

.item_no {
	width: 70px;
}

.item_subject {
	width: 300px;
	text-align: left;
}

.item_id {
	width: 100px;
}

.item_date {
	width: 200px;
}

.item_count {
	width: 70px;
}

.item_total {
	width: 100px;
	height: 20px;
	display: table-cell;
	color: black;
	font-family: 'Nanum Gothic', sans-serif;
	font-size: 13px;
	
}

.item_writeBtn {
	width: 650px;
	height: 20px;
	display: table-cell;
	/* padding-right: 10px; */
	
}

.item_pageNum {
	width: 600px;
	text-align: center;
	font-family: 'Nanum Gothic', sans-serif;
	font-size: 13px;
	
}

.item_pageNum input{
	background-color: transparent;
	color: black;
	border: 0px solid;
	cursor: pointer;
}

.item_subject a:link, .item_subject a:active, .item_subject a:visited{
	color: black;
	text-decoration: none;
}
</style>

<script>
function getId(id){
	return document.getElementById(id);
};
/* function init(){
	getId('btnSearch').onclick = findFunc;
	
	 getId('find').onkeyup = function(ev){
		if(ev.keyCode == 13){
			findFunc();
		}
	}; 
}
function findFunc(){
	search_form.action = "index2.jsp?inc_content=./board/list.jsp&nowPage=1";
	search_form.submit();
} */


function goPage(page){
/* 	alert("dddd"); */
	var ff = document.search_form;
	ff.nowPage.value = page;
	ff.action = "Main.jsp?inc_content=../board2/list.jsp";
	ff.submit();
}
function re(){
	alert("로그인을 해주세요");
};

</script>
</head>

<body>

	<jsp:useBean id="vo" class="board.BoardVo"></jsp:useBean>
	<jsp:setProperty property="*" name="vo" />
	<%
		// 검색어 세션 처리 
		if (request.getMethod().equals("POST")) { // POST 방식일 경우에만, 세션에 저장
			session.setAttribute("find", vo.getFind());
			
		} else { // GET 방식일 경우, 세션이 존재할 경우메나 setter
			if (session.getAttribute("find") != null)
				vo.setFind((String) session.getAttribute("find"));
		}
	
		 // 페이지 정보 유지 
		if(request.getParameter("nowPage") == null){
			if(session.getAttribute("nowPage") != null)
				vo.setNowPage((Integer)session.getAttribute("nowPage"));
		}
		else{
			session.setAttribute("nowPage", vo.getNowPage());
		}

		Board b = new Board();
		b.setVo(vo);
		b.setNowPage(vo.getNowPage());
		Vector<BoardVo> v = b.list();
		
		String sessionID = (String)session.getAttribute("mid");
	%>
	<div id='board_main'>
		<div align=center>
		<!-- <h1 id='board_h1'>Board</h1> -->

			<div id='board_pos'>
			
			<form name='search_form' method='post' action='Main.jsp?inc_content=../board2/list.jsp&nowPage=1'
			style='margin-bottom: 30px;' id="board_list_frm">
				<input type='search' name='find' id='find' placeholder="검색어를 입력하세요."
					value="<%=vo.getFind()%>" style="font-family: 'Nanum Gothic', sans-serif; width: 180px;font-size:14px;"> 
					
				<input type='submit' id='btnSearch' value='검색'>
				<input type='hidden' name='nowPage' value=<%=vo.getNowPage() %>>
			</form><p/>
			
				<div id='board_list'>
					<div id='list_no'>번호</div>
					<div id='list_subject'>제목</div>
					<div id='list_id'>작성자</div>
					<div id='list_date'>작성일</div>
					<div id='list_count'>조회수</div>

					<div id='list_line'
						style='background-color: #D2D2D2;'></div>
					<div id='list_line' style='background-color: #82B5DF;'></div>
				</div>

				<%
					if (v.size() == 0) {
				%> 
						등록된 글이 없습니다. 
				<%
					} else {
						for (int i = 0; i < v.size(); i++) {
							BoardVo vv = v.get(i);
							int serial = vv.getSerial();
							String id = vv.getMid();
							String title = vv.getSubject();
							Date date = vv.getMdate();
							int count = vv.getHit();
							int flag = vv.getFlag();
				%>
				<div class='board_item'>
					
					<%
						if (vv.getSerial() == vv.getGrp()) {
					%>
					<div class='item_no'>
						<%=serial%>
					</div>

					<div class='item_subject'>
					<%
						if(sessionID == null || sessionID == ""){
					%>
						<a href="#" onclick=re(); ><%=title%></a>
						<%}else{ %>
						<a href="Main.jsp?inc_content=../board2/view.jsp&serial=<%=serial%>"><%=title%></a>
					<%} %>
					</div>
					
					<%
						} else {
					%>
					
					<div class='item_no'>
						
					</div>

					<%
						String[] temp = vv.getDeep().split("-");
						int cnt = temp.length;
						
						
					%>
					<div class='item_subject'>
					<% if(sessionID != null){ %>
						<a href="Main.jsp?inc_content=../board2/view.jsp&serial=<%=serial%>">
					<%}else{ %>
						<a href="#" onclick='re();'>
					<%} %>
							<%for(int j=1;j<cnt;j++){ %>
								　
							<%} %>
							┗　
							<%if (flag == 1){ %>
							<font color='red'>[원본 글이 삭제됨]</font>
							<%} %>
							<%=title%>
						</a>
						
					</div>
					
					<%
						}
					%>
					
					<div class='item_id'>
						<%=id%>
					</div>
					<div class='item_date'>
						<%=date%>
					</div>
					<div class='item_count'>
						<%=count%>
					</div>

					<div id='list_line'
						style='background-color: #D2D2D2; margin-top: 2px;'></div>

				</div>

				<%
					}
					}
				%>

				<div id='list_line'
					style='background-color: #82B5DF; margin-bottom: 10px;'></div>

				<div id='item_etc'>
					<div class='item_total'>
						총 게시물 : <%=b.getTotSize()%>개<br/>
						<%-- 총 페이지 수 : <%=b.getTotPage()%><br/>
						총 블록 수 : <%=b.getTotBlock()%><br/>
						현재 블록 : <%=b.getNowBlock()%><br/>
						시작 페이지 : <%=b.getStartPage()%><br/>
						끝 페이지 : <%=b.getEndPage()%> --%>
					</div>
					<div class='item_writeBtn' align=right>
					<%
						//String sessionID = (String)session.getAttribute("mid");
						if(sessionID==null||sessionID==""){
					%>
						<input type=button value="글쓰기" id="list_input" OnClick=re();>
					<%}if(sessionID!=null){ %>
						
						<input type=button value="글쓰기" id="list_input"
							OnClick="location.href='Main.jsp?inc_content=../board2/register.jsp'"><p/>
					<%} %>
					</div>
				</div>

				<div class='item_pageNum'>
					<!-- 페이지 분리 영역 -->
					
					<%if(b.getNowBlock() > 1){ %>
					<input type='button' value='Start' onClick = 'goPage(1)'>
					<input type='button' value='Before' onClick = 'goPage(<%=b.getStartPage()-1%>)'>
					<%} %>
					[
					
					<%
						for(int p=b.getStartPage();p<=b.getEndPage();p++){					
					%>
					<input type='button' value=<%=p %> onClick = 'goPage(<%=p%>)' style="margin-right: 5px;font-size:13px;">
					
					<%} %>
					]
					
					<%if(b.getNowBlock() < b.getTotBlock()){ %>
					<input type='button' value='Next' onClick = 'goPage(<%=b.getEndPage()+1%>)'>
					<input type='button' value='End' onClick = 'goPage(<%=b.getTotPage()%>)'>
					<%} %>
				</div>

			</div>
		</div>
	</div>
	
	<!--<script>init();</script>-->
</body>
</html>